#ifndef VIDEOH
#define VIDEOH
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include "caml.h"


typedef struct PacketQueue

{
  AVPacketList *first_pkt, *last_pkt;
  int nb_packets;
  int size;
  SDL_mutex *mutex;
  SDL_cond *cond;
} PacketQueue;


typedef struct _video
{
  AVFormatContext *pFormatCtx;
  AVCodecContext *pCtx;
  AVCodec *pCodec;
  AVFrame *pRaw;
  AVFrame *pDat;
  uint8_t *buffer;
  struct SwsContext *Sctx;
  int videoStream, width, height, format;
  int quit2;

} video;


typedef struct _audio

{PacketQueue queuePaquet;
  int fluxAudio;
  AVCodecContext *pAudioCodec;
  AVFormatContext *pAudioFormat;
  SDL_AudioSpec specRecherche, spec;
  //int quit;
  void audio_callback(void *donnee, Uint8 *flux, int longueur);
  int audio_decode_frame(AVCodecContext *aCodecCtx, uint8_t *audio_buf, int buf_size);
  int packet_queue_put(PacketQueue *q, AVPacket *pkt);
  void packet_queue_init(PacketQueue *q);
  void audio_callback(void *donnee, Uint8 *flux, int longeur);
  int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block);

} audio ;

/*static struct custom_operations video_ops =
  {
    "custom_video",
    custom_finalize_default,
    custom_compare_default,
    custom_hash_default,
    custom_serialize_default,
    custom_deserialize_default
  };
*/
value video_init(value file);
value video_next(value cur);
value video_quit(value cur);
value video_debug_ppm(value cur, value file);
intlf_key();

#endif
